#!/bin/sh
ip netns add A
ip netns add B
ip netns add R1

ip link add name R1_A type veth peer name A_R1
ip link add name R1_B type veth peer name B_R1
ip link set R1_A netns R1
ip link set R1_B netns R1
ip link set A_R1 netns A
ip link set B_R1 netns B

#A
ip netns exec A ip addr add 192.168.0.1/24 dev A_R1
ip netns exec A ip link set A_R1 up
ip netns exec A ip link set lo up

#B
ip netns exec B ip addr add 192.168.0.1/24 dev B_R1
ip netns exec B ip link set B_R1 up
ip netns exec B ip link set lo up

#R1
ip netns exec R1 ip link add vif_ab type vrf table vab
ip netns exec R1 ip link add vif_cd type vrf table vcd
ip netns exec R1 ip link set vif_ab up
ip netns exec R1 ip link set vif_cd up

ip netns exec R1 ip link set R1_A master vif_ab
ip netns exec R1 ip link set R1_B master vif_cd

ip netns exec R1 ip addr add 192.168.0.254/24 dev R1_A
ip netns exec R1 ip addr add 192.168.0.254/24 dev R1_B

ip netns exec R1 ip link set R1_B up
ip netns exec R1 ip link set R1_A up
ip netns exec R1 ip link set lo up
